package com.example.untitled.util

import android.content.Context
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbManager
import android.widget.Toast

/*
 * @author hope.chen, QQ:77132995, email:kazeik@163.com
 * 2021-08-05 13:21
 * 类说明:
 */
object Utils {
    val MSG_RECEIPT_PRINT = "com.cs.jingsong/eatbusiness.receipt"
    val MSG_BTDEVICE_LIST = "com.cs.jingsong/eatbusiness.devices"
    val MSG_BTCONNECT = "com.cs.jingsong/eatbusiness.bt.connect"

    private var toast: Toast? = null

    fun getUsbDeviceFromName(context: Context, usbName: String?): UsbDevice? {
        val usbManager = context.getSystemService(Context.USB_SERVICE) as UsbManager
        val usbDeviceList = usbManager.deviceList
        return usbDeviceList[usbName]
    }

    fun showToast(context: Context?, message: String?) {
        if (toast == null) {
            toast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
        } else {
            toast!!.setText(message)
        }
        toast!!.show()
    }
}